<?php

	if ( !isset($_REQUEST["action"]) ) die();
	$action = $_REQUEST["action"];

	include( "bootstrap.php" );

	$data = array();
	
	if ( $action == "addComment" ) {
		$nodeid = $_REQUEST["nodeid"];
		$content = $_REQUEST["content"];
		$content = mysql_real_escape_string($content);
		$result = query("SELECT projectID FROM ".T_NODES." WHERE id='{$nodeid}'");
		$row = mysql_fetch_row($result);
		$projectid = $row[0];
		$result = query("INSERT INTO ".T_COMMENTS." (nodeID,projectID,content,createdOn) VALUES ('{$nodeid}', '{$projectid}', '{$content}', ".time().")");
		$commentid = mysql_insert_id();
		$result = query("SELECT * FROM ".T_COMMENTS." WHERE id='{$commentid}'");
		$obj = mysql_fetch_object($result);
		$obj->createdOn = date("F jS, Y @ g:ia", $obj->createdOn);
		$data["comment"] = $obj;
		dieSuccess("Comment successfully added", $data );
	}
	
	if ( $action == "deleteComment" ) {
		$commentid = $_REQUEST["commentid"];
		$result = query("DELETE FROM ".T_COMMENTS." WHERE id='{$commentid}'");
		dieSuccess( "Comment successfully deleted");
	}
?>